import ReactDOM from 'react-dom/client';
import App from './App';
import { Provider } from 'react-redux';
import { store, persistor } from '@/store';
import { PersistGate } from 'redux-persist/integration/react';
import { Spin } from 'antd';
import './reset.scss';
import './index.scss'

// 确保在MSW完全初始化后再渲染应用
async function initializeApp() {
  // 在开发环境下等待MSW初始化完成
  if (import.meta.env.DEV) {
    const { worker } = await import('./mocks/browser');
    await worker.start({
      onUnhandledRequest: 'bypass',
      quiet: true
    });
  }

  ReactDOM.createRoot(document.getElementById('root')!).render(
    <Provider store={store}>
      <PersistGate loading={<Spin /> } persistor={persistor}>
        <App />
      </PersistGate>
    </Provider>,
  );
}

initializeApp();